<template>
  <basic-container>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
          v-for="code in codes"
          :label="code.label"
          :name="code.name"
          :key="code.code"
      >
        <el-button type="primary" @click="copy(code)">直接复制</el-button>
        <pre>{{ code.code }}</pre>
      </el-tab-pane>
    </el-tabs>

  </basic-container>
</template>

<script>

import baseService from "../../../crud/baseService";

export default {
  name: "preview",
  data() {


    return {
      codes: [],
      activeName: 'second'
    }
  },
  methods: {
    init(row, item) {

      this.getInfo(row.id);
    },
    getInfo(id) {
      baseService.getData("/generator/gTableInfo/preview?id=" + id).then(res => {
        console.log(res.data)
        this.codes = res.data;
      });


    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    copy(code) {
      this.$Clipboard({
        text: code.code
      }).then(() => {
        this.$message.success('复制成功')
      }).catch(() => {
        this.$message.error('复制失败')
      });

    }
  }
}
</script>

<style scoped>

</style>
